import com.adobe.cairngorm.control.CairngormEventDispatcher;

import flash.events.MouseEvent;

import mx.events.MenuEvent;

import net.optix.ip.events.LogOutEvent;
import net.optix.ip.model.ModelLocator;

import views.ViewInstance;

[Bindable]
private var model:ModelLocator	=	ModelLocator.getInstance();

private var menu0:XMLList	=	
<>
	<menuitem label="User">
        <menuitem label="Register" event="Register"/>
        <menuitem label="Login" event="Login"/>
   	</menuitem>
   	<menuitem label="Invention"/>
</>;

private var menu1:XMLList	=	
<>
	<menuitem label="User" data="User">
    	<menuitem label="Edit Personal Information" event="Edit Personal Information"/>
       	<menuitem label="Change Password" event="Change Password"/>
       	<menuitem label="Log Out" event="Log Out"/>
   	</menuitem>
 	<menuitem label="Business" data="Client">
      	<menuitem label="Edit Company Information" event="Edit Company Information"/>
       	<menuitem label="Add New Inventor" event="Add New Inventor"/>
       	<menuitem label="View Inventors" event="View Inventors"/>
  	</menuitem>
  	<menuitem label="Invention" data="Invention" event="Register">
  		<menuitem label="Track Inventions" event="Track Inventions"/>
       	<menuitem label="Disclose New Invention" event="Disclose New Invention"/>
       	<menuitem label="View Inventions" event="View Inventions"/>
    </menuitem>
    
    <menuitem label="Trademark">
    	<menuitem label="View Trademarks" event="Trademark Docket"/>
    </menuitem>
    <menuitem label="Copyrights" event="Register">
    	<menuitem label="View Copyrights" event="Copyright Docket"/>
    </menuitem>
    <menuitem label="Trade Secret">
    	<menuitem label="Trade Secret" event="Trade Secret"/>
   </menuitem>
</>;

private var menu2:XMLList	=	
<>
	<menuitem label="User" data="User">
 		<menuitem label="Edit Personal Information" event="Edit Personal Information"/>
       	<menuitem label="Change Password" event="Change Password"/>
      	<menuitem label="Log Out" event="Log Out"/>
   	</menuitem>
   	<menuitem label="Invention" data="Invention">
      	<menuitem label="Disclose New Invention" event="Disclose New Invention"/>
       	<menuitem label="View Inventions" event="View Inventions"/>
  	</menuitem>
</>;

private var menu3:XMLList	=	
<>
	<menuitem label="User" data="User">
    	<menuitem label="Edit Personal Information" event="Edit Personal Information"/>
      	<menuitem label="Change Password" event="Change Password"/>
       	<menuitem label="Log Out" event="Log Out"/>
   	</menuitem>
   	<menuitem label="Firm" data="Firm">
       	<menuitem label="Edit Firm Information" event="Edit Firm Information"/>
       	<menuitem label="Add New Client" event="Add New Client"/>
      	<menuitem label="Add New Practitioner" event="Add New Practitioner"/>
       	<menuitem label="View Practitioners" event="View Practitioners"/>
  	</menuitem>
	<menuitem label="Invention">
		<menuitem label="Patent Docket" event="Patent Docket"/>
    	<menuitem label="Bid Request" event="Invention Bid Request"/>
	</menuitem>
    
    <menuitem label="Trademark Docket">
    	<menuitem label="Trademark Docket" event="Trademark Docket"/>
    	<menuitem label="Bid Request" event="Trademark Bid Request"/>
    </menuitem>
    <menuitem label="Copyright Docket">
    	<menuitem label="Copyright Docket" event="Copyright Docket"/>
    	<menuitem label="Bid Request" event="Copyright Bid Request"/>
    </menuitem>
</>;

private var menu4:XMLList	=	
<>
	<menuitem label="User" data="User">
   		<menuitem label="Edit Personal Information" event="Edit Personal Information"/>
       	<menuitem label="Change Password" event="Change Password"/>
        <menuitem label="Log Out" event="Log Out"/>
   	</menuitem>
   	<menuitem label="Practitioner" data="Practitioner">
      	<menuitem label="Add New Client" event="Add New Client"/>
   	</menuitem>
   	<menuitem label="Invention">
		<menuitem label="Patent Docket" event="Patent Docket"/>
	</menuitem>
</>;

private var menu5:XMLList	=	
<>
	<menuitem label="User">
    	<menuitem label="Edit Personal Information" event="Edit Personal Information"/>
     	<menuitem label="Change Password" event="Change Password"/>
       	<menuitem label="Log Out" event="Log Out"/>
 	</menuitem>     
   	<menuitem label="Manager">
      	<menuitem label="Clients List" event="Clients List"/>
      	<menuitem label="Firms List" event="Firms List"/>
  	</menuitem>
</>;
public var _role:int;

public function set role(value:int):void
{
	this._role	=	value;
	menus.dataProvider		=	null;
	switch(value)
	{
		case 0:
			menus.dataProvider	=	this.menu0;
			this.currentState	=	"user";
			break;
		case 1:
			menus.dataProvider	=	this.menu1;
			this.currentState	=	"client";
			break;
		case 2:
			menus.dataProvider	=	this.menu2;
			this.currentState	=	"inventor";
			break;
		case 3:
			menus.dataProvider	=	this.menu3;
			this.currentState	=	"firm";
			break;
		case 4:
			menus.dataProvider	=	this.menu4;
			this.currentState	=	"practitioner";
			break;
		case 5:
			menus.dataProvider	=	this.menu5;
			this.currentState	=	"manager";
			break;
	}
}

public function get role():int
{
	return this._role;
}

public function menuClick(event:MenuEvent):void
{
	var action:String	=	event.item.@event;

	switch(action)
	{
		case "Register":
			model.actionView	=	0;
			model.actionView	=	ViewInstance.Register;
			break;
		case "Login":
			model.actionView	=	0;
			model.actionView	=	ViewInstance.Login;
			break;
		case "Edit Personal Information":
			model.actionView	=	0;
			model.actionView	=	ViewInstance.EditPersonalInformation;
			break;
		case "Change Password":
			model.actionView	=	0;
			model.actionView	=	ViewInstance.ChangePassword;
			break;
		case "Log Out":
			var logOut:LogOutEvent	=	new LogOutEvent();
			com.adobe.cairngorm.control.CairngormEventDispatcher.getInstance().dispatchEvent(logOut);
			break;
		case "Edit Company Information":
			model.actionView	=	0;
			model.actionView	=	ViewInstance.EditBilling;
			break;
		case "Add New Inventor":
			model.actionView	=	0;
			model.actionView	=	ViewInstance.AddInventor;
			break;
		case "View Inventors":
			model.view			=	0;
			model.view			=	ViewInstance.ViewInventors;
			break;
		case "Edit Firm Information":
			model.actionView	=	0;
			model.actionView	=	ViewInstance.EditFirm;
			break;
		case "Add New Client":
			model.actionView	=	0;
			model.actionView	=	ViewInstance.AddClient;
			break;
		case "Add New Practitioner":
			model.actionView	=	0;
			model.actionView	=	ViewInstance.AddPractitioner;
			break;
		case "View Practitioners":	
			model.view			=	0;
			model.view			=	ViewInstance.ViewPractitioners;
			break;
		case "Disclose New Invention":
			model.actionView	=	0;
			model.actionView	=	ViewInstance.AddInvention;
			break;
		case "Clients List":
			model.view			=	0;
			model.view			=	ViewInstance.ViewClients;
			break;	
		case "Firms List":
			model.view			=	0;
			model.view			=	ViewInstance.ViewFirms;
			break;	
		case "Track Inventions":
			model.view			=	0;
			model.view			=	ViewInstance.TrackInventions;
			break;
		case "View Inventions":
			model.view			=	0;
			model.view			=	ViewInstance.ViewInventions;
			break;
		case "Invention Bid Request":
			model.view			=	0;
			model.view			=	ViewInstance.ViewBids;
			break;		
		case "Patent Docket":
			model.view			=	0;
			model.view			=	ViewInstance.ViewInventions;
			break;	
		case "Trademark Docket":
			model.view			=	0;
			model.view			=	ViewInstance.ViewTradeMarks;
			break;
		case "Trademark Bid Request":
			model.view			=	0;
			model.view			=	ViewInstance.ViewTradeMarkBids;
			break;
		case "Copyright Docket":
			model.view			=	0;
			model.view			=	ViewInstance.ViewCopyrights;
			break;
		case "Copyright Bid Request":
			model.view			=	0;
			model.view			=	ViewInstance.ViewCopyrightBids;
			break;
		case "Trade Secret":
			model.view			=	0;
			model.view			=	ViewInstance.TradeSecret;
			break;
		
	}
}

/*public function menuBarClick(event:MouseEvent):void
{
	var index:int	=	menus.selectedIndex;
	
	if(model.role == 1)
	{
		switch(index)
		{
			case 3:
				model.view			=	0;
				model.view			=	ViewInstance.TradeMark;
				break;
			case 4:
				model.view			=	0;
				model.view			=	ViewInstance.Copyrights;
				break;
			case 5:
				model.view			=	0;
				model.view			=	ViewInstance.TradeSecret;
				break;
		}
	}
	
	if(model.role == 3 || model.role == 4)
	{
		switch(index)
		{
			case 2:
				model.view			=	0;
				model.view			=	ViewInstance.ViewInventions;
				break;
			case 3:
				model.view			=	0;
				model.view			=	ViewInstance.ViewBids;
				break;
			case 4:
				model.view			=	0;
				model.view			=	ViewInstance.TradeMark;
				break;
			case 5:
				model.view			=	0;
				model.view			=	ViewInstance.Copyrights;
				break;
		}
	}
}*/